home *** CD-ROM | disk | FTP | other *** search
/ Aminet 9 / Aminet 9 (1995)(GTI - Schatztruhe)[!][Dec 1995].iso / Aminet / game / think / Dragon.lha / Dragon / Source / DragStart.s < prev    next >
Text File  |  1994-07-02  |  6KB  |  176 lines

  1. *************************************************************************
  2. *                                    *
  3. *              Dragon Startup Code.                *
  4. *              --------------------                *
  5. *                                    *
  6. *              --------------------                *
  7. *                 Nick Christie                *
  8. *               35 De Lisle Road                *
  9. *              Bournemouth BH3 7NF                *
  10. *                 Great Britain                *
  11. *              --------------------                *
  12. *                                    *
  13. * Tab size = 8.                                *
  14. *                                    *
  15. * Version 1.0    (18/12/92)                        *
  16. * ========================                        *
  17. * Startup for C using a4 base-relative data and registerized parameters    *
  18. * callable from WB or shell. Adapted from SAS/C 5.10 startup "c.a".    *
  19. * Sets up _SysBase, opens/closes dos.library, allows stack checking,    *
  20. * initializes _WBenchMsg and __StackPtr. Does not set up __ProgramName,    *
  21. * oserr, ONBREAK, etc. Calls @main (@ == register args) as:        *
  22. *    LONG rc [d0] = @main(char *cmdline [a0], ULONG cmdlen [d0])    *
  23. * Can't use exit(), as it needs other stuff.                *
  24. *                                    *
  25. * Version 1.1    (1/7/94)                        *
  26. * ======================                        *
  27. * Edited for V40 includes.                        *
  28. *                                    *
  29. * Assembles under GenAm3 with:                        *
  30. *    genam INCDIR <whatever> ALINK DragStart.s            *
  31. * Should assemble easily under other assemblers, me thinks.        *
  32. *                                    *
  33. *************************************************************************
  34.  
  35. *************************************************************************
  36. ******************************  INCLUDES  *******************************
  37. *************************************************************************
  38.  
  39.         INCLUDE        "exec/exec.i"
  40.         INCLUDE        "exec/funcdef.i"
  41.         INCLUDE        "exec/exec_lib.i"
  42.         INCLUDE        "dos/dosextens.i"
  43.  
  44. *************************************************************************
  45. *****************************  REFERENCES  ******************************
  46. *************************************************************************
  47.  
  48.         XREF        _LinkerDB    ; linker defined base value
  49.         XREF        __BSSBAS    ; linker defined base of BSS
  50.         XREF        __BSSLEN    ; linker defined length of BSS
  51.  
  52.         XREF        @main        ; name of C routine to start
  53.         XREF        _DOSBase    ; must supply externally
  54.  
  55.         XDEF        _SysBase    ; exec.library base
  56.         XDEF        _WBenchMsg    ; Workbench Startup Msg
  57.         XDEF        __StackPtr    ; sp for quick exit
  58.         XDEF        __base        ; for stack checking
  59.  
  60. *************************************************************************
  61. *****************************  DEFINITIONS  *****************************
  62. *************************************************************************
  63.  
  64. ABSEXECBASE    EQU        4
  65.  
  66. *************************************************************************
  67. ********************************  START  ********************************
  68. *************************************************************************
  69. * Called from shell with cmd line info, from WB with nothing.
  70. *
  71. * In:    a0 = ptr to cmd line (if shell)
  72. *    d0 = len of cmd line (if shell)
  73. * Out:    d0 = return code (if shell)
  74. *
  75. *************************************************************************
  76.  
  77.         SECTION        TEXT,CODE
  78.  
  79.         RSRESET                    ; stack map.
  80.         rs.b        4
  81. SAVEDREGS    rs.b        13*4
  82. STACKSIZE    rs.b        4
  83.  
  84. Start:        movem.l        d1-d6/a0-a6,-(a7)
  85.  
  86.         move.l        a0,a2            ; save command pointer
  87.         move.l        d0,d2            ;  and command length
  88.         lea.l        _LinkerDB,a4        ; load data base reg
  89.         move.l        ABSEXECBASE.w,a6
  90.  
  91.         lea.l        __BSSBAS,a3        ; get base of BSS seg
  92.         moveq.l        #0,d1
  93.         move.l        #__BSSLEN,d0        ; len of BSS in longs
  94.         bra.s        S_ClrBSS2
  95. S_ClrBSS1:    move.l        d1,(a3)+        ; clear BSS segment
  96. S_ClrBSS2:    dbra        d0,S_ClrBSS1
  97.  
  98.         move.l        sp,__StackPtr(A4)    ; save stack ptr
  99.         move.l        a6,_SysBase(a4)        ; save SysBase
  100.         clr.l        _WBenchMsg(A4)        ; clr WB msg ptr
  101.  
  102.         moveq.l        #0,d0            ; clear any pending
  103.         move.l        #$3000,d1        ;   signals
  104.         jsr        _LVOSetSignal(a6)
  105.  
  106.         lea.l        DOSName(pc),a1        ; attempt to open
  107.         moveq.l        #0,d0            ;  DOS library
  108.         jsr        _LVOOpenLibrary(a6)
  109.         move.l        d0,_DOSBase(a4)
  110.         bne.s        S_DosOpen
  111.         moveq.l        #100,d0            ; failed, return
  112.         bra.s        S_Exit            ;  error level 100
  113.  
  114. S_DosOpen:    move.l        ThisTask(a6),a3        ; ptr to my process
  115.         tst.l        pr_CLI(a3)        ; called from WB ?
  116.         beq.s        S_FromWB        ; yes...
  117.  
  118. S_FromShell:    move.l        sp,d0            ; d0 = top of stack
  119.         sub.l        STACKSIZE(sp),d0    ; d0 = bottom of stk
  120.         addi.l        #128,d0            ; + 128 for overflow
  121.         move.l        d0,__base(a4)        ; save for stack check
  122.         bra.s        S_GoMain        ; ready to call program
  123.  
  124. S_FromWB:    move.l        TC_SPLOWER(a3),d0    ; get stack bottom
  125.         addi.l        #128,d0            ; + 128 for overflow
  126.         move.l        d0,__base(a4)        ; save for checking
  127.  
  128.         lea.l        pr_MsgPort(a3),a0    ; now wait for and
  129.         jsr        _LVOWaitPort(a6)    ;  get the WB startup
  130.         lea.l        pr_MsgPort(a3),a0    ;   message...
  131.         jsr        _LVOGetMsg(a6)
  132.         move.l        d0,_WBenchMsg(a4)    ; save ptr to WB msg,
  133.         movea.l        d0,a2            ;  also into a2
  134.         moveq.l        #0,d2            ; cmdlen = 0 for WB
  135.  
  136. S_GoMain:    movea.l        a2,a0            ; move cmdlen and
  137.         move.l        d2,d0            ;  cmdline into a0/d0
  138.         jsr        @main(pc)        ; call C program
  139.  
  140. S_Exit:        movea.l        __StackPtr(a4),sp    ; restore original sp
  141.         move.l        d0,-(a7)        ;  & save return code
  142.  
  143.         tst.l        _WBenchMsg(a4)        ; came from WB ?
  144.         beq.s        S_CloseDOS        ; nope...
  145.  
  146.         move.l        ABSEXECBASE.w,a6    ; yes...reply the WB msg
  147.         jsr        _LVOForbid(a6)        ; but Forbid() first so
  148.         movea.l        _WBenchMsg(a4),a1    ; WB doesn't UnLoadSeg()
  149.         jsr        _LVOReplyMsg(a6)    ;  us before we're done
  150.  
  151. S_CloseDOS:    move.l        _DOSBase(a4),d0
  152.         beq.s        S_Return
  153.         movea.l        d0,a1
  154.         move.l        ABSEXECBASE.w,a6
  155.         jsr        _LVOCloseLibrary(a6)
  156.  
  157. S_Return:    move.l        (a7)+,d0        ; retrieve return code
  158.         movem.l        (a7)+,d1-d6/a0-a6
  159.         rts
  160.  
  161. DOSName:    dc.b        'dos.library',0
  162.  
  163. *************************************************************************
  164. ********************************  DATA  *********************************
  165. *************************************************************************
  166.  
  167.         SECTION        __MERGED,BSS
  168.  
  169. __base:        ds.l        1
  170. _SysBase:    ds.l        1
  171. _WBenchMsg:    ds.l        1
  172. __StackPtr:    ds.l        1
  173.  
  174.         END
  175.  
  176.